package io.renren.modules.member.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.modules.member.dao.CommQueryDao;
import io.renren.modules.member.service.CommQueryService;
import io.renren.modules.member.vo.ExamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CommQueryServiceImpl implements CommQueryService {

    @Autowired
    private CommQueryDao commQueryDao;

    private Page<Map<String, Object>> getPage(Map<String, Object> params) {
        //分页参数
        long curPage = 1;
        long limit = 10;
        if(params.get(Constant.PAGE) != null){
            curPage = Long.parseLong((String)params.get(Constant.PAGE));
        }
        if(params.get(Constant.LIMIT) != null){
            limit = Long.parseLong((String)params.get(Constant.LIMIT));
        }
        //分页对象
        Page<Map<String, Object>> page = new Page<>(curPage, limit);
        //分页参数
//        params.put(Constant.PAGE, page);
        return page;
    }

    public PageUtils queryPageExam(Map<String, Object> params) {
        Page<Map<String, Object>> page = getPage(params);
        page.setRecords(commQueryDao.findPageExam(page, params));
        return new PageUtils(page);
    }

    public List<ExamVO> queryAllExam(Map<String, Object> params) {
        return commQueryDao.findAllExam(params);
    }


}
